/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-08-25
 * Time: 20:39
 */
public class demo9 {
    private static int flag = 0;
    private static Object locker = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread c = new Thread(()->{
            synchronized (locker){
                while(flag != 0){
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("c");
                flag = 1;
                locker.notifyAll();
            }
        });
        Thread b=  new Thread(()->{
            synchronized (locker){
                while(flag != 1){
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("b");
                flag = 2;
                locker.notifyAll();
            }
        });
        Thread a = new Thread(()->{
            synchronized (locker){
                while(flag != 2){
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("a");
                flag = 0;
                locker.notifyAll();
            }
        });
        c.start();
        b.start();
        a.start();

    }
}
